package com.lbj.yuanxi.yx001

import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.res.Resources
import android.graphics.PixelFormat
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.telephony.TelephonyManager
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.lbj.yuanxi.R

class FloatingWindowActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.yx001_activity_floating_window)
    }

    fun onShowCircle(v: View) {
        println("包名：$packageName")
        println(Settings.canDrawOverlays(this))
        if (!Settings.canDrawOverlays(this)) {
            val intent =
                Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName"))
            startActivityForResult(intent, 1001)
        } else {
            FloatingWindowManager.getInstance(this).showCircleView()

            // density:2.75 相对密度，相对于160的密度
            println("density:${Resources.getSystem().displayMetrics.density}")
            // scaledDensity:2.75
            println("scaledDensity:${Resources.getSystem().displayMetrics.scaledDensity}")
            // 密度 densityDpi:440
            println("densityDpi:${Resources.getSystem().displayMetrics.densityDpi}")
            // 屏幕宽度像素点：widthPixels:1080
            println("widthPixels:${Resources.getSystem().displayMetrics.widthPixels}")
            // 屏幕高度像素点：heightPixels:2134
            println("heightPixels:${Resources.getSystem().displayMetrics.heightPixels}")

//            var serviceIntent = Intent(this, FloatingWindowService::class.java)
//            startService(serviceIntent)

//            TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
//            String deviceid = tm.getDeviceId();
//            String tel = tm.getLine1Number();
//            String  imei = tm.getSimSerialNumber();
//            String imsi = tm.getSubscriberId();
//            String simState = tm.getSimState();

            val  telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
//            println("deviceId = ${telephonyManager?.deviceId}")
//            println("line1Number = ${telephonyManager?.line1Number}")
//            println("simSerialNumber = ${telephonyManager?.simSerialNumber}")
            telephonyManager.allCellInfo.forEach {
                println(it.timeStamp)
            }

        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 1001) {
            if (!Settings.canDrawOverlays(this)) {
                Toast.makeText(this, "没有弹窗权限", Toast.LENGTH_SHORT).show()
            } else {
                FloatingWindowManager.getInstance(this).showCircleView()
            }
        }
    }
}